def is_valid(r,c,path):
    for i in range(len(path)):
        if (r==i) or (c==path[i]) or (r-c==i-path[i]) or (r+c==i+path[i]): return False 
    return True

def dfs(ans,path,n):
    if len(path)==n:
        tmp=[]
        for i in path:
            tmp.append('.'*i+'Q'+'.'*(n-i-1))
        ans.append(tmp)
        return 
    r=len(path)
    for c in range(n):
        if is_valid(r,c,path):
            path.append(c)
            dfs(ans,path,n)
            path.pop()

def solve(n):
    ans=[]
    dfs(ans,[],n)
    return ans 

print(solve(4))
print(solve(1))